package com.os.opencv.java.chapter4;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Threshold {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        //读取图像文件并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/MATT-MAC/matt_workspace/OS-OpenCV_workspace/view.jpg",
                Imgcodecs.IMREAD_GRAYSCALE);
        HighGui.imshow("src", src);
        HighGui.waitKey(0);

        Mat dst = new Mat();
        //二值化处理并在屏幕上显示，阈值=90
        Imgproc.threshold(src, dst, 90, 255, Imgproc.THRESH_BINARY);
        HighGui.imshow("threshold=90", dst);
        HighGui.waitKey(0);

        //二值化处理并在屏幕上显示，阈值=120
        Imgproc.threshold(src, dst, 120, 255, Imgproc.THRESH_BINARY);
        HighGui.imshow("threshold=120", dst);
        HighGui.waitKey(0);

        //二值化处理并在屏幕上显示，阈值=180
        Imgproc.threshold(src, dst, 180, 255, Imgproc.THRESH_BINARY);
        HighGui.imshow("threshold=180", dst);
        HighGui.waitKey(0);

        System.exit(0);

    }
}
